package cn.wolfcode.p2p.business.service.impl;

import cn.wolfcode.p2p.base.domain.RealAuth;
import cn.wolfcode.p2p.base.query.QueryObject;
import cn.wolfcode.p2p.business.domain.PlatformBankInfo;
import cn.wolfcode.p2p.business.domain.UserBankInfo;
import cn.wolfcode.p2p.business.mapper.PlatformBankInfoMapper;
import cn.wolfcode.p2p.business.service.IPlatformBankInfoService;
import cn.wolfcode.p2p.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

@Service@Transactional
public class PlatformBankInfoServiceImpl implements IPlatformBankInfoService {
        @Autowired
        private PlatformBankInfoMapper platformBankInfoMapper;

        @Override
        public PageResult listAll(QueryObject qo) {
                 //先查出COunt,如果COUNT为0,返回空集合
                 int row = platformBankInfoMapper.selectCount(qo);
                 if(row==0){
                     return new PageResult(Collections.EMPTY_LIST,0,1,qo.getPageSize());
                 }
                 List<RealAuth> list =platformBankInfoMapper.queryAll(qo);
                 return new PageResult(list,row,qo.getCurrentPage(),qo.getPageSize());
        }

        @Override
        public void saveOrUpdate(PlatformBankInfo platformBankInfo) {
                if(platformBankInfo.getId()!=null){
                        //更新
                        platformBankInfoMapper.updateByPrimaryKey(platformBankInfo);
                }else{
                        platformBankInfoMapper.insert(platformBankInfo);
                }
        }

        @Override
        public List<PlatformBankInfo> selectAll() {
                return platformBankInfoMapper.selectAll();
        }
}
